*******************************************************************************
* 5. Prepare the household interview data for wave 3

use "$data_input/OWWA_HH_Wave3.dta", clear

* First cleaning
missings dropvars, force
compress


* Relevant variables
local intent_ofw "hh_k12_intention_ofw_3 hh_childloop_1_m5_if_ofw_3 hh_childloop_2_m5_if_ofw_3"
local perceived_effect_mig "hhi_i1_exp_financial_3 hhi_i2_exp_stdliving_3 hhi_i3_exp_housing_3 hhi_i4_exp_health_3 hhi_i5_exp_educ_3 hhi_i6_exp_family_3 hhi_i7_exp_social_3"
 

* Recode questions with a Yes/No answer to 1=Yes, 0=No ,97 98 to missing. missing set to .
lab define l_yesno 0 "No" 1 "Yes"

* Intention of the remaining household members to work as OFW as reported by main respondent
* NOTE: K12.Do you have any intentions of being an OFW? was asked only to the main respondent. 
* Intention of remaining HH members (except HH main respondent and children) to become OFW was not asked

gen hh_intent_ofw_3=hh_k12_intention_ofw_3
lab var hh_intent_ofw_3 "Intent of household to work as an OFW"

* Intention of the remaining household members to work as OFW as self-reported in individual interviews 
gen hh_intent_child1_ofw_3=hh_childloop_1_m5_if_ofw_3
lab var hh_intent_child1_ofw_3 "Intent of child to work as an OFW"

gen hh_intent_child2_ofw_3=hh_childloop_2_m5_if_ofw_3
lab var hh_intent_child2_ofw_3 "Intent of child to work as an OFW"

lab val hh_intent_ofw_3 hh_intent_child1_ofw_3 hh_intent_child2_ofw_3 l_yesno

* Perceived effect of migrantís emigration on the household
gen hh_financial_3=hhi_i1_exp_financial_3
gen hh_stdliving_3=hhi_i2_exp_stdliving_3 
gen hh_housing_3=hhi_i3_exp_housing_3 
gen hh_health_3=hhi_i4_exp_health_3 
gen hh_educ_3=hhi_i5_exp_educ_3 
gen hh_famlife_3=hhi_i6_exp_family_3 
gen hh_soclife_3=hhi_i7_exp_social_3

* Recode Perceived effect of emigration to the household, 97 98 set to missing
lab define l_effect_emig 3 "Better" 2 "Same" 1 "Worse"
foreach var of varlist hh_financial_3 hh_stdliving_3 hh_housing_3 hh_health_3 hh_educ_3 hh_famlife_3 hh_soclife_3 {
	recode `var' (4/.c=.c) (3=1) (1=3)
	lab val `var' l_effect_emig
}

* Create Binary variables for erceived effect of emigration to the household (migration has made better)

foreach var in financial stdliving housing health educ famlife soclife {
	recode hh_`var'_3 (3=1) (1/2=0), gen(b_hh_`var'_3)
	lab val b_hh_`var'_3 l_yesno
}

* Index for total effect is the mean over the other variables
egen hh_efftot_3 = rowmean(hh_financial_3 hh_stdliving_3 hh_housing_3 hh_health_3 hh_educ_3 hh_famlife_3 hh_soclife_3)
egen b_hh_efftot_3 = rowmean(b_hh_financial_3 b_hh_stdliving_3 b_hh_housing_3 b_hh_health_3 b_hh_educ_3 b_hh_famlife_3 b_hh_soclife_3)

*Future plans of DW
gen hh_stay_ph_3=.c
replace hh_stay_ph_3=1 if hh_a6_plan_end_contract_3==1 // plan if HSW is abroad
replace hh_stay_ph_3=0 if hh_a6_plan_end_contract_3!=1 & hh_a6_plan_end_contract_3<.
lab var hh_stay_ph_3 "HSW plans to stay in the Philippines"
lab val hh_stay_ph_3 l_yesno

gen hh_stay_employer_3=.c
replace hh_stay_employer_3=1 if hh_a6_plan_end_contract_3==2 | hh_a6_plan_end_contract_3==5
replace hh_stay_employer_3=0 if hh_a6_plan_end_contract_3==1 | hh_a6_plan_end_contract_3==3 | hh_a6_plan_end_contract_3==4| hh_a6_plan_end_contract_3==6| hh_a6_plan_end_contract_3==7
lab var hh_stay_employer_3 "HSW plans to continue working for current employer"
lab val hh_stay_employer_3 l_yesno

* Financial coordination
* Note: in wave 2, we asked if they discuss amount of remittances with the family. 
* In HSW wave 3, we asked who decides on the amount and use of remittances
gen hh_dis_budget_3 = 1 if hh_g1_discuss_budget_3 <=2
replace hh_dis_budget_3 = 0 if hh_g1_discuss_budget_3==3
gen hh_disagree_use_3=hh_g4_disagree_remit_3

lab var hh_dis_budget_3 "HH: Discussed budget"
lab var hh_disagree_use_3 "HH: Had disagreement on use of remittances"
lab val hh_dis_budget_3 hh_disagree_use_3 l_yesno

* Demand for extra remittances
gen hh_sent_more_3= hh_g10_excess_remit_3
lab var hh_sent_more_3 "HH: HSW sent more remittances than planned"
lab val hh_sent_more_3 l_yesno

gen hh_fam_extra_mon_3=hh_g11_family_ask_more_3
lab var hh_fam_extra_mon_3 "Family asked for extra money"
lab val hh_fam_extra_mon_3 l_yesno

gen hh_remit_bank_3 = 0 if hh_g8_remittance_channel_3<.
replace hh_remit_bank_3 = 1 if hh_g8_remittance_channel_3==1
lab var hh_remit_bank_3 "Remittances sent via bank transfer"
lab val hh_remit_bank_3 l_yesno

* Recode remittances reported by the hh
rename hh_g6_no_receive_money_times_no_ hh_freq_remit_3

gen hh_am_remit_3=.c
*use usd-variable from cleaning do-file
replace hh_am_remit_3=hh_g7_amount_receive_money_con_3
replace hh_am_remit_3=0 if  hh_g5_freq_remit_3==6 //HSW did not send money 

gen hh_remit_total_3 = hh_am_remit_3 * hh_freq_remit_3

* Recode savings of the HSW as reported by the hh
* use usd-variable from cleaning do-file
gen hh_hsw_sav_3=hh_h5_savings_hsw_con_3

* Recode savings set aside by family
* use usd-variable from cleaning do-file
gen hh_fam_sav_3=hh_h4_savings_family_con_3

* Total savings
gen hh_total_sav_3=hh_hsw_sav_3 + hh_fam_sav_3
lab var hh_total_sav_3 "HH: Total amount of savings (in USD)"


* Log of savings and remittances
gen l_hh_total_sav_3=log(hh_total_sav_3+1)
gen l_hh_hsw_sav_3=log(hh_hsw_sav_3+1)
gen l_hh_fam_sav_3=log(hh_fam_sav_3+1)
gen l_hh_am_remit_3=log(hh_am_remit_3+1)
gen l_hh_remit_total_3=log(hh_remit_total_3+1)

lab var l_hh_total_sav_3 "HH: Total savings (log)"
lab var l_hh_hsw_sav_3 "HH: HSW savings (log)"
lab var l_hh_fam_sav_3 "HH: Family savings (log)"
lab var l_hh_am_remit_3 "HH: Remittances most recent transaction (log)"
lab var l_hh_remit_total_3 "HH:  Remittances in past six months (log)"

lab var hh_financial_3 "HH: Effect on financial security"
lab var hh_stdliving_3 "HH: Effect on standard of living" 
lab var hh_housing_3 "HH: Effect on housing status"
lab var hh_health_3 "HH: Effect on on health" 
lab var hh_educ_3 "HH: Effect on on education" 
lab var hh_famlife_3 "HH: Effect on on family life"
lab var hh_soclife_3 "HH: Effect on on social life"

lab var b_hh_financial_3 "HH: Migration improved financial security"
lab var b_hh_stdliving_3 "HH: Migration improved standard of living" 
lab var b_hh_housing_3 "HH: Migration improved housing status"
lab var b_hh_health_3 "HH: Migration improved health" 
lab var b_hh_educ_3 "HH: Migration improved education" 
lab var b_hh_famlife_3 "HH: Migration improved family life"
lab var b_hh_soclife_3 "HH: Migration improved social life"
lab var hh_efftot_3 "HH: Migration had positive effect"
lab var hh_fam_sav_3 "HH: Family savings (PHP)"
lab var hh_hsw_sav_3 "HH: HSW savings (PHP)"
lab var hh_total_sav_3 "HH: Total savings (PHP)"

lab var hh_am_remit_3 "HH: Remittances most recent transaction (PHP)"
lab var hh_remit_total_3 "HH: Remittances in past six months (PHP)"
lab var hh_freq_remit_3 "HH: Frequency of remittances"

* Well-being of main respondent
gen hh_happy_3=hhj_j1a_how_happy_3
gen hh_calm_3=hhj_j1b_how_calm_3 
 
recode hh_happy_3 hh_calm_3 (1=5) (2=4) (3=3) (4=2) (5=1) (98 99=.c)
lab var hh_happy_3 "Happier"
lab var hh_calm_3 "Calmer"

lab def l_reversecode 5 "All of the time" 4 "Most of the time" 3 "Some of the time" 2 "A little of the time" 1 "None of the time"
lab val hh_happy_3 hh_calm_3 l_reversecode

gen hh_nervous_3=hhj_j1c_how_nervous_3 
recode hh_nervous_3 (98 99=.c)
lab var hh_nervous_3 "Less nervous"

gen hh_downheart_3=hhj_j1d_how_downheart_3
recode hh_downheart_3 (98 99=.c)
lab var hh_downheart_3 "Less down hearted and blue"

gen hh_downdumps_3=hhj_j1e_how_downdumps_3
recode hh_downdumps_3 (98 99=.c)
lab var hh_downdumps_3 "Less down in the dumps"

gen hh_pain_3=hhj_j1f_how_pain_3
recode hh_pain_3 (98 99=.c)
lab var hh_pain_3 "Less pain"

lab def l_mhcode  1 "All of the time" 2 "Most of the time" 3 "Some of the time" 4 "A little of the time" 5 "None of the time"
lab val hh_nervous_3 hh_downheart_3 hh_downdumps_3 hh_pain_3 l_mhcode

gen hh_mental_health_3=hh_happy_3 + hh_calm_3 + hh_nervous_3 + hh_downheart_3 + hh_downdumps_3 + hh_pain_3
lab var hh_mental_health_3 "Mental Health Index"

gen hh_repair_status_3=hh_hhe4_repair_3
lab val hh_repair_status_3 hh_hhe4_repair_3 
lab var hh_repair_status_3 "State of repair of the house/building"

* Recode posessions to binary variables
foreach item in car motor washing_machine aircon computer gasrange refrigerator landline cp tv dvd {
	capture gen b_`item'_3 = hh_c9_`item'_3>0 if hh_c9_`item'_3<.
}

lab var b_car_3 "HH owns car"
lab var b_motor_3 "HH owns motorcycle"
lab var b_washing_machine_3 "HH owns washingmachine"
lab var b_aircon_3 "HH owns aircondition"
lab var b_computer_3 "HH owns computer"
lab var b_gasrange_3 "HH owns gasrange"
lab var b_refrigerator_3 "HH owns refrigerator"
lab var b_landline_3 "HH owns landline"
lab var b_cp_3 "HH owns mobile phone"
lab var b_tv_3 "HH owns TV"
lab var b_dvd_3 "HH owns DVD player"

lab val b_car_3 b_motor_3 b_washing_machine_3 b_aircon_3 b_computer_3 b_gasrange_3 b_refrigerator_3 b_landline_3 b_cp_3 b_tv_3 b_dvd_3 l_yesno

* Schooling intentions for children as reported by main respondent
* NOTE: We asked schooling intentions in the individual interviews but with very few answers

lab def l_edu_intent 1 "Elementary schooling" 2 "High school" 3 "Technical/vocational education" 4 "College" 5 "Master/PhD"

* What is the highest level you want to complete
gen hh_c1_edu_intent_3=hh_childloop_1_m1_child_educ_3 
gen hh_c2_edu_intent_3=hh_childloop_2_m1_child_educ_3 
lab val hh_c1_edu_intent_3 hh_c2_edu_intent_3 l_edu_intent

lab def l_gocollege  1 "Very likely" 2 "Likely" 3 "Not very likely" 4 "Not likely at all"

* How likely to attend college or university
gen hh_c1_gocollege_3=hh_childloop_1_m2_child_college_ 
gen hh_c2_gocollege_3=hh_childloop_2_m2_child_college_
lab val hh_c1_gocollege_3 hh_c2_gocollege_3 l_gocollege

*replace . with .c
qui ds, has(type numeric)
local x=r(varlist)
recode `x' (.=.c) 

save "$data_prep/owwa_hh_w3_edited.dta", replace
